package org.dzms.commons;

public class sqlHandler {
	private String cond ="";
	public String getCond() {
		return cond;
	}
	public void setCond(String cond) {
		this.cond = cond;
	}
		//语句进入时为：“列名 =值(=) 列名#=值(模糊查询like)列名=x-y（and） 列名>=值（>=）”
		//等于直接等于某值 或者希望模糊等于某值 再或者等于一个范围
		public String getConditionSQL(){
			String sql= "";
			if(cond!=null){
				//分割语句
				String [] conds = cond.split(",");
				for(String cond:conds){
					if(cond.indexOf("#=")!=-1){
						String [] kv = cond.split("#=");
						sql+=" "+kv[0]+" like '%"+kv[1]+"%' ";
					}else if (cond.indexOf("-")!=-1){
						sql+=" "+cond.replace("=", " between ").replace("-", " and ");
					}else{
						sql+=" "+cond;
					}
					
					sql+=" and ";
				}
			}
			
			sql = sql.replaceFirst("( and )$", "");
			return sql;
		}
}
